//
//  DiZhiViewController.m
//  GuoBang
//
//  Created by fengshuai on 16/4/28.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "DiZhiViewController.h"
#import "DiZhiTableViewCell.h"
#import "AddDiZhiViewController.h"

@interface DiZhiViewController ()<UITableViewDataSource, UITableViewDelegate, sendAddressDelegate>
{
    
    DiZhiTableViewCell *dizhiCell;
    NSMutableArray *addArr;
}

@property (nonatomic, strong) UITableView *setTableView;

@end

@implementation DiZhiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNVA];
    [self setupUI];
    [self setupData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


- (void)setupNVA
{
    UIImage *image = [UIImage imageNamed:@"ico_arrowleft.png"];
    UIImage *image1 = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithImage:image1 style:UIBarButtonItemStyleDone target:self action:@selector(leftAction:)];
    self.navigationItem.leftBarButtonItem = left;
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(69, 10, self.view.frame.size.width -138, 34)];
    self.navigationItem.titleView = label;
    label.text = @"地址管理";
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont boldSystemFontOfSize:18];
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStyleDone target:self action:@selector(rightAction)];
    right.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = right;
}

- (void)leftAction:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupData
{
      addArr = [NSMutableArray arrayWithObject:@"1"];
    
}

- (void)setupUI
{
//    self.view.backgroundColor = RGBCOLOR(211,211,211);
    self.setTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT ) style:UITableViewStyleGrouped];
    self.setTableView.delegate = self;
    self.setTableView.dataSource = self;

    
    self.setTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.setTableView];
 
    
    
}








- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return addArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customcell"];
    
    
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DiZhiTableViewCell" owner:self options:nil];
    if (nib.count > 0) {
        dizhiCell = [nib objectAtIndex:0];
        
        cell = dizhiCell;
    }
    
    
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
 
}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}


- (void)rightAction
{
    AddDiZhiViewController *addVC = [AddDiZhiViewController new];
    addVC.delegate = self;
    [self.navigationController pushViewController:addVC animated:YES];
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

-(void)sendBack
{
    [addArr addObject:@"1"];
    [self.setTableView reloadData];
    
    
}








@end
